#define DATE _DATE   // to avoid a conflict between DATE() and Windows DATE def

#include <windows.h>
#include <extend.h>

//----------------------------------------------------------------------------//

LPSTR date( void )
{
   SYSTEMTIME st;
   LPSTR date = "00/00/0000";

   GetLocalTime( &st );

   date[ 0 ] = ( st.wDay / 10 ) + '0';
   date[ 1 ] = ( st.wDay % 10 ) + '0';

   date[ 3 ] = ( st.wMonth / 10 ) + '0';
   date[ 4 ] = ( st.wMonth % 10 ) + '0';

   date[ 6 ] = ( st.wYear / 1000 ) + '0';
   st.wYear  = st.wYear % 1000;

   date[ 7 ] = ( st.wYear / 100 ) + '0';
   st.wYear  = st.wYear % 100;

   date[ 8 ] = ( st.wYear / 10 ) + '0';
   st.wYear  = st.wYear % 10;

   date[ 9 ] = ( st.wYear ) + '0';

   return date;
}

//----------------------------------------------------------------------------//

WORD dow( void )
{
   SYSTEMTIME st;

   GetLocalTime( &st );

   return st.wDayOfWeek;
}

//----------------------------------------------------------------------------//

LPSTR time( void )
{
   SYSTEMTIME st;
   LPSTR time = "00:00:00";

   GetLocalTime( &st );

   time[ 0 ] = ( st.wHour / 10 ) + '0';
   time[ 1 ] = ( st.wHour % 10 ) + '0';
   time[ 3 ] = ( st.wMinute / 10 ) + '0';
   time[ 4 ] = ( st.wMinute % 10 ) + '0';
   time[ 6 ] = ( st.wSecond / 10 ) + '0';
   time[ 7 ] = ( st.wSecond % 10 ) + '0';

   return time;
}

//----------------------------------------------------------------------------//

CLIPPER CTOD()
{
   _retd( _parc( 1 ) );
}

//----------------------------------------------------------------------------//

CLIPPER DOW()
{
   _retni( dow() );
}

//----------------------------------------------------------------------------//

CLIPPER DTOC()
{
   BYTE date[ 11 ];
   LPSTR szDate = _pard( 1 );

   date[  0 ] = szDate[ 0 ];
   date[  1 ] = szDate[ 1 ];
   date[  2 ] = '/';
   date[  3 ] = szDate[ 2 ];
   date[  4 ] = szDate[ 3 ];
   date[  5 ] = '/';
   date[  6 ] = szDate[ 4 ];
   date[  7 ] = szDate[ 5 ];
   date[  8 ] = szDate[ 6 ];
   date[  9 ] = szDate[ 7 ];
   date[ 10 ] = '0';

   _retc( date );
}

//----------------------------------------------------------------------------//

CLIPPER DAY()
{
   WORD wDay = 0;

   wDay += ( _pard( 1 )[ 0 ] - '0' ) * 10;
   wDay += ( _pard( 1 )[ 1 ] - '0' );

   _retni( wDay );
}

//----------------------------------------------------------------------------//

CLIPPER MONTH()
{
   WORD wMonth = 0;

   wMonth += ( _pard( 1 )[ 2 ] - '0' ) * 10;
   wMonth += ( _pard( 1 )[ 3 ] - '0' );

   _retni( wMonth );
}

//----------------------------------------------------------------------------//

CLIPPER VERSION()
{
   _retc( "FIVE 1.0" );
}

//----------------------------------------------------------------------------//

CLIPPER YEAR()
{
   WORD wYear = 0;

   wYear += ( _pard( 1 )[ 4 ] - '0' ) * 1000;
   wYear += ( _pard( 1 )[ 5 ] - '0' ) *  100;
   wYear += ( _pard( 1 )[ 6 ] - '0' ) *   10;
   wYear += ( _pard( 1 )[ 7 ] - '0' );

   _retni( wYear );
}

//----------------------------------------------------------------------------//

#undef DATE

CLIPPER DATE()
{
   _retd( date() );
}

//----------------------------------------------------------------------------//

CLIPPER TIME()
{
   _retc( time() );
}

//----------------------------------------------------------------------------//

CLIPPER SECONDS()
{
   _retnl( GetTickCount() / 14 );
}

//----------------------------------------------------------------------------//

CLIPPER LCHDIR()
{
   if( PCOUNT() )
      _retl( SetCurrentDirectory( _parc( 1 ) ) );
   else
      _retl( FALSE );
}

//----------------------------------------------------------------------------//
